package cn.lingyangwl.agile.common.core.utils;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @author shenguangyang
 */
@Getter
@AllArgsConstructor
public enum ExcelContentType {
    XLS("xls", "application/vnd.ms-excel"),
    XLSX("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
    ;
    private final String name;
    private final String contentType;

    public static ExcelContentType ofByName(String name) {
        return Arrays.stream(values())
                .filter(e -> StrUtil.equalsIgnoreCase(e.name, name)).findFirst().orElse(null);
    }

    public static ExcelContentType ofByContentType(String contentType) {
        return Arrays.stream(values())
                .filter(e -> StrUtil.equalsIgnoreCase(e.contentType, contentType)).findFirst().orElse(null);
    }
}
